/**
 * Copyright (C), 2001-2031, www.bosssof.com.cn
 * FileName: Enum.java
 * Author: YuXingZh
 * Date: 16/5/2024 上午10:42
 * Description:
 * <p>
 * History:
 * Date          Author   Version  Desc
 * 2024-01-01    bosssoft  1.0.0   initialize this file
 */
package org.boss.server;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * @className: protocol
 * @description:
 * 解决什么问题：
 *  定义了协议内容
 * @author: YuXingZh
 * @date: 15/5/2024下午10:38
 * @since 1.0
 **/
public class FileServer {
    public static void main(String[]args) throws Exception{
        //两个线程组
        EventLoopGroup bossGroup = new NioEventLoopGroup();
        EventLoopGroup workerGroup = new NioEventLoopGroup();

        try {
            //启动服务器
            ServerBootstrap serverBootstrap = new ServerBootstrap();
            serverBootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).
                    childHandler(new FileServerInitializer());

            //绑定端口
            ChannelFuture channelFuture = serverBootstrap.bind(18899).sync();
            channelFuture.channel().closeFuture().sync();
        }finally {
            // 关闭线程组
            bossGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();
        }
    }
}
